﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpIM.Http
{
    public class HttpApiRoute
    {
        public string ClassRouteName { get; set; }
        public string MethodRouteName { get; set; }
        public string DefaultParameterName { get; set; }
        public string FullRoutePath { get; set; }
        public static HttpApiRoute Parse(HttpRequest request)
        {
            var className = "Home";
            var methodName = "Index";
            string pName = null;
            var paths = RequestPath.GetPaths(request.Url);
            if (paths.Length == 1)
            {
                className = paths[0];
            }
            else if (paths.Length == 2)
            {
                className = paths[0];
                methodName = paths[1];
            }
            else if (paths.Length == 3)
            {
                className = paths[0];
                methodName = paths[1];
                pName = paths[2];
            }
            return new HttpApiRoute { ClassRouteName = "/" + className, MethodRouteName = "/" + methodName, DefaultParameterName = pName, FullRoutePath = "/" + string.Join("/", paths) };
        }
    }
}
